package com.utils.event
{
	import flash.display.DisplayObject;
	import flash.geom.Point;
	
	public class EventController
	{
		private static var eventDispose:EventController;
		private var eventDispatch:EventDispatch;
		public function EventController()
		{
			if(eventDispose){
				throw Error('不能重复实例化!');
			}else{
				eventDispose = this;
			}
			
		}
		
		public static function get instance():EventController{
			if(!eventDispose) eventDispose = new EventController();
			return eventDispose;
		}
		
		/**
		 * 抛出事件
		 * @param type 事件类型 自定
		 * @param object 事件中需要携带的数据
		 */		
		public function dispatch(type:int,object:Object = null):void{
			if(!eventDispatch) eventDispatch = new EventDispatch();
			eventDispatch.addEventListener(UserEvent.USER_EVENT,onEventHandler);
			eventDispatch.dispatch(type,object);
		}
		
		/**接收抛出的事件,并处理*/		
		private function onEventHandler(e:UserEvent):void{
			eventDispatch.removeEventListener(UserEvent.USER_EVENT,onEventHandler);
			eventDispatch.clearEvent();
			//此处添加处理事件的代码
		}
		
		
	}
}
import flash.events.Event;

class UserEvent extends Event
{
	/**事件类型*/		
	public static const USER_EVENT:String = 'USER_EVENT';
	
	public var object:Object;
	public var type:int;
	
	public function UserEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false)
	{
		super(type, bubbles, cancelable);
	}
}


import flash.display.DisplayObject;
import flash.events.EventDispatcher;
import flash.geom.Point;

class EventDispatch extends EventDispatcher{

	private var userEvent:UserEvent;
	/**广播*/		
	public function dispatch(type:int,object:Object = null):void{
		userEvent = new UserEvent(UserEvent.USER_EVENT);
		userEvent.object= object;
		userEvent.type = type;
		dispatchEvent(userEvent);
	}
	
	/**清理*/	
	public function clearEvent():void{
		userEvent = null;
	}
}